SELECT *
FROM BPS_Patients
WHERE StatusText = 'Active'
AND InternalID IN (SELECT InternalID FROM PastHistory WHERE ACUTECODE = 2 AND RecordStatus = 1)
AND NOT InternalID IN (
	SELECT InternalID
	FROM INVOICES
	WHERE RECORDSTATUS = 1
	AND INVOICEID IN (
		SELECT INVOICEID FROM SERVICES WHERE MBSITEM in (721, 723, 732, 92024, 92025, 92028, 229, 230, 233, 92055, 92056, 92059, 965, 967, 92029, 92030, 392, 393, 92060, 92061)
	AND services.SERVICESTATUS IN (0,2)
	AND RECORDSTATUS = 1))
ORDER BY surname, firstname;

-- Patients with a chronic disease or condition and no care plan item billed